part of shop;

class LikedPage extends StatefulWidget {
  List<Map?> liked = [];
  Future<List<String>?> _getLocalLikedListString() async {
    SharedPreferences uPrefs = await SharedPreferences.getInstance();
    var localLikedListString = uPrefs.getStringList("Liked");
    return localLikedListString;
  }

  LikedPage({Key? key}) : super(key: key);

  @override
  State<LikedPage> createState() => _LikedPageState();
}

class _LikedPageState extends State<LikedPage> {
  // ignore: unused_element
  _deleteProductLiked() async {
    _delete() async {
      SharedPreferences uPrefs = await SharedPreferences.getInstance();
      uPrefs.setStringList("Liked", []);
    }

    AppTool().showCenterTipsAlter(context, _delete, "您确定要删除收藏得商品吗", "温馨提示");
    setState(() {});
  }

  Widget get builderLiked {
    if (widget.liked.isEmpty) {
      return Container(child: Text("什么都没有"));
    }
    List<Widget> _list = [];
    for (int i = 0; i < widget.liked.length; i++) {
      _list.add(Container(
        margin: const EdgeInsets.fromLTRB(30, 15, 30, 15),
        decoration: const BoxDecoration(
          color: Colors.white,
          //boxShadow: true,
          borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
        ),
        child: ElevatedButton(
            style: ButtonStyle(
                backgroundColor: MaterialStateProperty.all(Colors.white)),
            onPressed: () {},
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Image.network(widget.liked[i]?["product_coverimg"][0]),
                  flex: 1,
                ),
                Expanded(
                  child: Column(
                    children: <Widget>[
                      Text(
                        widget.liked[i]?["product_price"],
                        style: const TextStyle(color: Colors.black),
                      ),
                      Text(widget.liked[i]?["product_name"],
                          style: const TextStyle(color: Colors.black)),
                      Container(
                        decoration: const BoxDecoration(
                          color: Colors.white,
                          //boxShadow: true,
                          borderRadius:
                              BorderRadius.vertical(top: Radius.circular(20)),
                        ),
                        child: ElevatedButton(
                            onPressed: () {}, child: const Text("联系卖家")),
                      )
                    ],
                  ),
                  flex: 2,
                )
              ],
            )),
      ));
    }
    return ListView(
      children: _list,
      shrinkWrap: true,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            //leading: null,
            automaticallyImplyLeading: true,
            title: const Text('购物车'),
            actions: <Widget>[
              IconButton(
                icon: Icon(Icons.ac_unit),
                onPressed: () {},
              ),
            ]),
        body: Material(
            child: CustomScrollView(
                scrollDirection: Axis.vertical,
                slivers: <Widget>[
              SliverList(
                  delegate: SliverChildListDelegate([
                FutureBuilder(
                    future: widget._getLocalLikedListString().then((value) {
                      if (value != null) {
                        for (int i = 0; i < value.length; i++) {
                          widget.liked.add(json.decode(value[i]));
                        }
                      }
                      //assert(widget.liked! is List<Map>);
                    }),
                    builder: (BuildContext context,
                        AsyncSnapshot<List<String>?> snapshot) {
                      return builderLiked;
                    })
              ]))
            ])));
  }
}

class MyLiked extends StatefulWidget {
  final Map<dynamic, dynamic>? likedMap;
  MyLiked({Key? key, this.likedMap}) : super(key: key);

  @override
  State<MyLiked> createState() => _MyLikedState();
}

class _MyLikedState extends State<MyLiked> {
  @override
  Widget build(BuildContext context) {
    return Column(children: <Widget>[
      Container(
        decoration: BoxDecoration(
          //boxShadow: true,
          border: Border.all(color: Colors.white),
          borderRadius: BorderRadius.circular(20),
          color: Colors.green,
        ),
        child: ElevatedButton(
            onPressed: () {},
            child: Row(
              children: <Widget>[
                Container(
                  child: Image.network(widget.likedMap!["product_coverimg"][0]),
                )
              ],
            )),
      ),
      ElevatedButton(
          onPressed: () async {
            final ImagePicker _picker = ImagePicker();
            // TODO：Pick an image
            final XFile? image =
                await _picker.pickImage(source: ImageSource.gallery);
          },
          child: Text("购买"))
    ]);
  }
}
// ///商品卡片
// class LikedCard extends StatelessWidget {
//   final Image _image;
//   const LikedCard({Key? key,required this._image}) : super(key: key);
//
//   @override
//   Widget build(BuildContext context) =>ListTile(
//     leading:CircleAvatar(
//       child: _image,
//     ),
//   );
// }

